#!/bin/bash

#查询地址变量
URL=$1
#时间变量
DATES="$(date +%Y.%m.%d-%H:%M:%S)"

#获取本机IPV4地址IPV6地址
echo "您的IPV4地址：" | tee -a $URL.log
curl -s4 icanhazip.com | tee -a $URL.log
echo "您的IPV6地址:" | tee -a $URL.log
curl -s6 icanhazip.com | tee -a $URL.log 
echo "==============================================" |tee -a $URL.log
echo "$DATES开始$URL查询开始.." | tee -a $URL.log
#公共DNS解析服务器地址集
for DNS in "1.0.0.1" "1.1.1.1" "1.2.4.8" "101.101.101.101" "101.102.103.104" "101.132.183.99" "101.226.4.6" "101.236.28.23" "101.6.6.6" "106.14.152.170" "112.121.178.187" "112.4.0.55" "114.114.114.114" "114.114.115.115" "115.159.157.26" "115.159.158.38" "115.159.220.214" "115.159.96.69" "116.228.111.118" "117.50.11.11" "119.23.248.241" "119.28.28.28" "119.29.105.234" "119.29.29.29" "119.6.6.6" "120.77.212.84" "122.114.245.45" "123.123.123.123" "123.123.123.124" "123.125.81.6" "123.206.61.167" "123.207.137.88" "124.161.87.155" "140.207.198.6" "156.154.70.1" "156.154.71.1" "168.95.1.1" "168.95.192.1" "176.103.130.130" "176.103.130.131" "178.79.131.110" "180.168.255.118" "180.76.76.76" "182.254.116.116" "182.254.118.118" "185.184.222.222" "185.222.222.222" "193.112.15.186" "195.46.39.39" "195.46.39.40" "199.85.126.10" "199.85.127.10" "199.91.73.222" "2001:da8::666" "202.100.64.68" "202.101.172.35" "202.101.224.69" "202.101.226.68" "202.102.128.68" "202.102.134.68" "202.102.152.3" "202.102.154.3" "202.102.213.68" "202.102.224.68" "202.102.227.68" "202.103.0.68" "202.103.224.68" "202.103.225.68" "202.103.24.68" "202.106.0.20" "202.106.195.68" "202.45.84.58" "202.55.11.100" "202.55.21.85" "202.96.128.166" "202.96.128.68" "202.96.128.86" "202.96.134.33" "202.96.209.133" "202.96.209.5" "202.96.64.68" "202.96.69.38" "202.97.224.68" "202.97.224.69" "202.98.0.68" "202.98.192.67" "202.98.198.167" "202.98.5.68" "202.99.104.68" "202.99.160.68" "202.99.166.4" "202.99.192.66" "202.99.192.68" "202.99.224.68" "202.99.224.8" "202.99.96.68" "203.80.96.10" "203.80.96.9" "208.67.220.220" "208.67.222.222" "210.2.4.8" "210.21.196.6" "210.22.70.3" "210.22.84.3" "211.137.191.26" "211.138.180.2" "211.138.180.3" "216.146.35.35" "216.146.36.36" "218.2.135.1" "218.2.2.2" "218.201.96.130" "218.30.118.6" "218.30.19.40" "218.4.4.4" "218.6.200.139" "218.85.152.99" "218.85.157.99" "219.141.136.10" "219.141.140.10" "219.146.0.132" "219.146.1.66" "219.147.1.66" "219.147.198.230" "219.147.198.242" "219.148.162.31" "219.150.32.132" "221.11.1.67" "221.11.1.68" "221.12.1.227" "221.12.33.227" "221.131.143.69" "221.5.203.98" "221.5.88.88" "221.6.4.66" "221.6.4.67" "221.7.92.98" "222.172.200.68" "222.246.129.80" "222.74.39.50" "222.85.85.85" "222.88.88.88" "223.5.5.5" "223.6.6.6" "2400:da00::6666" "4.2.2.1" "4.2.2.1" "4.2.2.2" "4.2.2.2" "40.73.101.101" "45.90.28.249" "45.90.30.249" "52.80.66.66" "59.51.78.211" "60.191.244.5" "61.128.128.68" "61.128.192.68" "61.132.163.68" "61.134.1.4" "61.139.2.69" "61.147.37.1" "61.153.177.196" "61.153.81.75" "61.166.150.123" "61.178.0.93" "63.223.94.66" "64.6.64.6" "64.6.65.6" "8.20.247.20" "8.26.56.26" "8.8.4.4" "8.8.8.8" "80.80.80.80" "80.80.81.81" "9.9.9.9" "118.244.224.124" "202.141.178.13" "203.195.182.150" "115.29.189.118" "202.38.93.153" "180.153.225.136" "202.141.162.123" "202.141.176.93" 

do 
{ 
#进行DNS解析,并截取返回的服务器IP地址值
nslookup $URL $DNS |grep Address |grep -v "#" |awk '{print $2}'  >> /tmp/$URL.log 
}&

done 
#等待上一条执行结果
sleep 5
#查询结果统计
cat /tmp/$URL.log |sort |uniq -c |sort |tee -a $URL.log

echo "==============================================" |tee -a $URL.log
echo "$DATES查询完成，结果查看$URL.log"

#清除本次查询缓存记录
rm -f /tmp/$URL.log
